﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XS = System.Xml.Serialization;

namespace Wheels
{
    public static class BinaryUtility
    {
#pragma warning disable 1591

        #region Dummy Utils

        private class DummyReader : XS.XmlSerializationReader
        {
            protected override void InitCallbacks() { }
            protected override void InitIDs() { }

            public static byte[] HexToBytes(string hex)
            {
                return ToByteArrayHex(hex);
            }
        }

        private class DummyWriter : XS.XmlSerializationWriter
        {
            protected override void InitCallbacks() { }

            public static string BytesToHex(byte[] bin)
            {
                return FromByteArrayHex(bin);
            }
        }

        #endregion

        public static string BytesToHex(this IEnumerable<byte> bin)
        {
            return BytesToHex(bin.ToArray());
        }

        public static string BytesToHex(this byte[] bin)
        {
            return DummyWriter.BytesToHex(bin);
        }

        public static byte[] HexToBytes(this string hex)
        {
            return DummyReader.HexToBytes(hex);
        }
    }
}
